package com.woniu.controller;

import com.woniu.entity.dto.OrderParamDTO;
import com.woniu.service.OrderService;
import com.woniu.util.ResponseData;
import com.woniu.util.ResponseEnum;
import lombok.AllArgsConstructor;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

@RestController
@RequestMapping("/order")
@AllArgsConstructor
public class OrderController {
    private OrderService orderService;
    @PostMapping("/addOrder")
    public ResponseData<?> addOrder(@RequestBody OrderParamDTO orderParamDTO){
        try {
            //校验参数
            if (orderParamDTO.getAddrId() == null || CollectionUtils.isEmpty(orderParamDTO.getCartIds()))
                return ResponseData.fail(ResponseEnum.PARAM_ERROR);
            return  orderService.addOrder(orderParamDTO);
        } catch (InterruptedException | ParseException e) {
            throw new RuntimeException(e);
        }
    }

}
